var e = require;
var t = module;
var n = exports;
var o,
    i =
        (this && this.__extends) ||
        ((o = function (e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function (e, t) {
            function n() {
                this.constructor = e;
            }
            o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
        }),
    r =
        (this && this.__decorate) ||
        function (e, t, n, o) {
            var i,
                r = arguments.length,
                a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
            else
                for (var s = e.length - 1; 0 <= s; s--)
                    (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
            return 3 < r && a && Object.defineProperty(t, n, a), a;
        };
Object.defineProperty(n, "__esModule", {value: !0});
var a,
    s = e("index"),
    c = e("player-info"),
    l = e("events"),
    u = e("player-coin"),
    p = e("sound"),
    h = e("vibrate"),
    d = e("war-coin"),
    f = e("panel-manager"),
    m = e("player-war"),
    t = cc._decorator,
    e = t.ccclass,
    t = t.property,
    e =
        ((a = cc.Component),
        i(y, a),
        (y.prototype.start = function () {
            var n = this;
            this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this),
                this.adsLockBg.getComponent(cc.Animation).on(cc.Animation.EventType.FINISHED, function (e, t) {
                    "Adunlock" == t.name &&
                        ((n.adsLockBg.active = !1),
                        (n.isAdsLocking = !1),
                        (n.isLock = !1),
                        l.operEvent.emit({action: l.default.adsCanUnlock, data: {cellIdx: n.curIdx}}));
                });
        }),
        (y.prototype.setSelectNode = function (e) {
            this.selectNode = e;
        }),
        (y.prototype.setIsNoTouch = function (e) {
            this.isNoTouch = e;
        }),
        (y.prototype.getCellData = function () {
            return this.cellData;
        }),
        (y.prototype.onTouchStart = function () {
            this.isNoTouch ||
                this.isAdsLocking ||
                this.isLock ||
                (l.operEvent.emit({action: l.default.cellTouch, data: {cellIdx: this.curIdx, isChoose: this.isChoose}}),
                c.playerInfo.getStartTime());
        }),
        (y.prototype.getIsLock = function () {
            return this.isLock;
        }),
        (y.prototype.getIsAdsLocking = function () {
            return this.isAdsLocking;
        }),
        (y.prototype.onAdsLock = function () {
            f.PanelManager.ins.open("prefab/panel/warUnlockPanel", {
                continueHandler: this.onAdsLockCallBack.bind(this)
            });
        }),
        (y.prototype.onAdsLockCallBack = function () {
            var e = m.playerWar.getUseADAreaCount();
            m.playerWar.setUseADAreaCount(e + 1),
                l.operEvent.emit({action: l.default.cellAdsLock, data: {cellIdx: this.curIdx}});
        }),
        (y.prototype.setLock = function (e) {
            (this.adsLockBg.active = !1), !e && this.isLock && this.unlockItem(), (this.isLock = e);
        }),
        (y.prototype.unlockItem = function () {
            (this.isAdsLocking = !1), (this.adsLockBg.active = !1);
        }),
        (y.prototype.showAdsUnlock = function () {
            (this.isAdsLocking = !0), (this.adsLockBg.active = !0), (this.isLock = !0);
        }),
        (y.prototype.unlockAds = function () {
            this.adsLockBg.getComponent(cc.Animation).play("Adunlock"),
                p.sound.play(p.Sound.GETAREA),
                h.vibrate.play(h.VibrateNewType.SHORT),
                s.platform.trackEvent("getADArea", {bool: !0, type: "challenge"});
        }),
        (y.prototype.setIsAds = function (e) {
            this.isAds = e;
        }),
        (y.prototype.isAdsCell = function () {
            return this.isAds;
        }),
        (y.prototype.init = function (e, t, n, o, i) {
            (this.curIdx = e),
                t && this.cleanCell(),
                this.setLock(this.isAdsCell()),
                this.isAdsCell() && this.showAdsUnlock(),
                (this.mergeBg.active = !1),
                this.isLock
                    ? i && i()
                    : ((this.cellData = o),
                      !this.cellData || this.cellData.length <= 0
                          ? i && i()
                          : ((this.firstNum = this.cellData[0].num),
                            this.loadCoins(this.cellData, n, i),
                            this.cellData.length != this.coinItems.length &&
                                console.error("init....", this.curIdx, this.cellData.length, this.coinItems.length)));
        }),
        (y.prototype.loadCoins = function (e, t, n) {
            var o = u.playerCoin.getCoinMaxCount(),
                i = Math.min(e.length, o);
            e.length > o && console.log("coins data count over max error,data:", e, " maxCount:", o);
            for (var r = 0; r < i; ++r) {
                var a = (0.5 * o + r - i) * this.coinYDistance,
                    s = cc.instantiate(t);
                (s.parent = this.coinParent), s.setPosition(0, a);
                var c = s.getComponent(d.default),
                    a = new u.coinData();
                (a.cellIdx = this.curIdx),
                    (a.num = e[r].num),
                    (a.isUnknown = e[r].isUn),
                    c.init(a),
                    this.coinItems.push(c),
                    s.setSiblingIndex(0);
            }
            this.checkCoinsTouch(), n && n();
        }),
        (y.prototype.checkCoinsTouch = function () {
            if (
                (this.cellData.length != this.coinItems.length &&
                    console.error("checkCoinsTouch....", this.curIdx, this.cellData.length, this.coinItems.length),
                !this.isLock)
            ) {
                if (((this.coinTouchCount = 0), null == this.firstNum))
                    return (
                        (this.mergeBg.active = this.isCanMerge()),
                        void (
                            this.mergeBg.active &&
                            (p.sound.play(p.Sound.TZ_FULL), h.vibrate.play(h.VibrateNewType.SHORT))
                        )
                    );
                for (
                    var e = this.cellData.length, t = 0;
                    t < e && this.cellData[t].num === this.firstNum && !this.cellData[t].isUn;
                    ++t
                ) {
                    var n = this.coinItems[t];
                    n
                        ? (n.setTouch(!0), this.coinTouchCount++)
                        : console.error("items idx error:", t, this.coinItems.length, this.curIdx);
                }
                (this.mergeBg.active = this.isCanMerge()),
                    this.mergeBg.active && (p.sound.play(p.Sound.TZ_FULL), h.vibrate.play(h.VibrateNewType.SHORT));
            }
        }),
        (y.prototype.isCanMerge = function () {
            var e = u.playerCoin.getCoinMaxCount();
            return this.coinTouchCount === e;
        }),
        (y.prototype.setUpBgActvie = function () {
            this.selectNode;
        }),
        (y.prototype.setChoose = function (t, n, o) {
            var i = this;
            this.isChoose = t;
            var r = this.isCanMerge();
            r && t && (this.mergeBg.active = !1), t && this.setUpBgActvie(!0);
            for (var a = this.coinItems.length, s = this, e = 0; e < a; ++e)
                !(function (e) {
                    s.coinItems[e].setChoose(
                        t,
                        function () {
                            e === a - 1 &&
                                (r &&
                                    !t &&
                                    ((i.mergeBg.active = !0),
                                    h.vibrate.play(h.VibrateNewType.SHORT),
                                    p.sound.play(p.Sound.TZ_FULL)),
                                n && n());
                        },
                        o
                    );
                })(e);
            0 === a && n && n();
        }),
        (y.prototype.getFirstNum = function () {
            return this.firstNum;
        }),
        (y.prototype.getCanAddCount = function () {
            return u.playerCoin.getCoinMaxCount() - this.coinItems.length;
        }),
        (y.prototype.getCoinItemCount = function () {
            return this.coinItems.length;
        }),
        (y.prototype.getMoveCoin = function (e) {
            var t = Math.min(this.coinTouchCount, e),
                e = this.coinItems.splice(0, t);
            return (
                e && 0 < e.length && (this.cellData.splice(0, t), this.refreshItem()),
                this.cellData.length != this.coinItems.length &&
                    console.error("getMoveCoin....", this.curIdx, this.cellData.length, this.coinItems.length),
                e
            );
        }),
        (y.prototype.refreshItem = function () {
            0 < this.cellData.length ? (this.firstNum = this.cellData[0].num) : (this.firstNum = null),
                this.checkCoinsTouch();
        }),
        (y.prototype.getPosition = function (e, t, n, o) {
            var i = u.playerCoin.getCoinMaxCount(),
                r = this.coinParent.convertToWorldSpaceAR(cc.Vec2.ZERO),
                r = e.convertToNodeSpaceAR(r),
                n = (0.5 * i + t - (this.coinItems.length + n)) * this.coinYDistance;
            return (r.y += n * o), r;
        }),
        (y.prototype.addCoins = function (e) {
            for (
                var t = u.playerCoin.getCoinMaxCount(), n = this.coinItems.length + e.length, o = [], i = 0;
                i < e.length;
                i++
            ) {
                var r = e[i];
                o.push(r.getData());
            }
            for (i = e.length - 1; 0 <= i; --i) {
                var a = (0.5 * t + i - n) * this.coinYDistance;
                (r = e[i]).node.removeFromParent(),
                    (r.node.parent = this.coinParent),
                    r.node.setPosition(0, a),
                    r.reseat(this.curIdx, !0, !1);
            }
            (this.coinItems = e.concat(this.coinItems)),
                (this.cellData = o.concat(this.cellData)),
                this.cellData.length != this.coinItems.length &&
                    console.error("addCoins....", this.curIdx, this.cellData.length, this.coinItems.length);
        }),
        (y.prototype.updateCell = function () {
            for (var e = this.coinItems.length, t = 0; t < e; ++t) this.coinItems[t].setTouch(!1);
            this.refreshItem();
        }),
        (y.prototype.cleanCell = function () {
            for (var e = this.coinItems.length, t = 0; t < e; ++t) {
                var n = this.coinItems[t];
                (n.node.active = !1), l.operEvent.emit({action: l.default.recoveryCoin, data: {coin: n}});
            }
            (this.coinItems = []),
                (this.cellData = []),
                (this.isChoose = !1),
                (this.firstNum = null),
                (this.coinTouchCount = 0);
        }),
        (y.prototype.isOneNumber = function () {
            if (0 === this.cellData.length) return !0;
            for (var e = !1, t = 0; t < this.cellData.length; t++)
                if (this.cellData[t].num != this.firstNum) {
                    e = !0;
                    break;
                }
            return !e;
        }),
        (y.prototype.getCoinTouchCount = function () {
            return this.coinTouchCount;
        }),
        r([t(cc.Node)], y.prototype, "upBg", void 0),
        r([t(cc.Node)], y.prototype, "coinParent", void 0),
        r([t(cc.Node)], y.prototype, "mergeBg", void 0),
        r([t(cc.Node)], y.prototype, "adsLockBg", void 0),
        r([t({displayName: "金币Y方向的间隔"})], y.prototype, "coinYDistance", void 0),
        r([t({displayName: "合成金币时间间隔"})], y.prototype, "mergeTime", void 0),
        r([t({displayName: "合成金币缩小时间间隔"})], y.prototype, "mergeScaleTime1", void 0),
        r([t({displayName: "合成金币放大时间间隔"})], y.prototype, "mergeScaleTime2", void 0),
        r([t({displayName: "合成金币回弹时间间隔"})], y.prototype, "mergeScaleTime3", void 0),
        r([t({displayName: "问号在金币上坐标Y的偏移"})], y.prototype, "questionMarkOffY", void 0),
        r([e], y));
function y() {
    var e = (null !== a && a.apply(this, arguments)) || this;
    return (
        (e.upBg = null),
        (e.coinParent = null),
        (e.mergeBg = null),
        (e.adsLockBg = null),
        (e.coinYDistance = 21),
        (e.mergeTime = 0.03),
        (e.mergeScaleTime1 = 0.03),
        (e.mergeScaleTime2 = 0.03),
        (e.mergeScaleTime3 = 0.03),
        (e.questionMarkOffY = 42),
        (e.isLock = !0),
        (e.curIdx = 0),
        (e.coinItems = []),
        (e.cellData = []),
        (e.isChoose = !1),
        (e.firstNum = null),
        (e.coinTouchCount = 0),
        (e.isAdsLocking = !1),
        (e.isNoTouch = !1),
        (e.isAds = !1),
        (e.selectNode = null),
        e
    );
}
n.default = e;
